package com.scuec.groupfive.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.MockExam;
import com.scuec.groupfive.mapper.MockExamMapper;
import com.scuec.groupfive.service.MockExamService;
import com.scuec.groupfive.vo.MockExamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service  // 添加@Service注解，声明为Spring服务组件
public class MockExamServiceImpl implements MockExamService {

    @Autowired  // 自动注入MockExamMapper
    private MockExamMapper mockExamMapper;

    @Override
    public PageInfo<MockExam> getMockExamPages(Integer pageNum, Integer pageSize) {
        // 启动分页
        PageHelper.startPage(pageNum, pageSize);
        // 查询所有模拟考试记录
        List<MockExam> mockExams = mockExamMapper.getAllMockExams();
        // 返回分页信息
        return new PageInfo<>(mockExams);
    }

    @Override
    public PageInfo<MockExamVO> getMockExamByUsername(String username, Integer pageNum, Integer pageSize) {
        // 启动分页
        PageHelper.startPage(pageNum, pageSize);
        // 根据用户名查询模拟考试记录
        List<MockExamVO> mockExams = mockExamMapper.getMockExamsByUsername(username);
        // 返回分页信息
        return new PageInfo<>(mockExams);
    }

    @Override
    public Map<String, Object> getExamStatsByUsername(String username) {
        // 直接调用Mapper获取统计信息
        return mockExamMapper.getExamStatsByUsername(username);
    }
}